﻿using System.Windows;
using System.Windows.Controls;
using PersonaLibrary.ViewModel.PrintViewModel;

namespace PersonaLibrary.View.PrintView
{
	/// <summary>
	/// Interaction logic for OrderView.xaml
	/// </summary>
	public partial class OrderView : IView
	{
		public OrderView()
		{
			InitializeComponent();
		}
		
		private OrderViewModel ViewModel
		{
			get { return DataContext as OrderViewModel; }
		}

		private void Up_Click(object sender, RoutedEventArgs e)
		{
			Button button = (Button) sender;
			Data.Employee employee = button.DataContext as Data.Employee;

			if(employee != null)
			{
				int originalIndex = ViewModel.Employees.IndexOf(employee);
				if(originalIndex != 0)
					ViewModel.Employees.Move(originalIndex, originalIndex - 1);
			}
		}

		private void Down_Click(object sender, RoutedEventArgs e)
		{
			Button button = (Button)sender;
			Data.Employee employee = button.DataContext as Data.Employee;

			if (employee != null)
			{
				int originalIndex = ViewModel.Employees.IndexOf(employee);
				if (originalIndex != ViewModel.Employees.Count - 1)
					ViewModel.Employees.Move(originalIndex, originalIndex + 1);
			}
		}
	}
}
